package com.diy.sigmund.diycommon.designpatterns.singlecasemodel;

/**
 * 静态内部类实现单例
 *
 * @author ylm-sigmund
 * @since 2021/8/16 17:54
 */
public class StaticInnerClass {

    /**
     * 私有化构造方法
     */
    private StaticInnerClass() {
    }

    /**
     * 对外提供获取实例的公共方法
     *
     * @return ContextHolder
     */
    public static StaticInnerClass getInstance() {
        return StaticInnerClass.InnerClass.INSTANCE;
    }

    /**
     * 静态内部类实现单例
     */
    private static class InnerClass {

        private static final StaticInnerClass INSTANCE = new StaticInnerClass();
    }

    /**
     * 测试ok
     */
    public static void main(String[] args) {
        final StaticInnerClass instance = StaticInnerClass.getInstance();
        final StaticInnerClass instance1 = StaticInnerClass.getInstance();
        System.out.println(instance == instance1);
    }
}
